001    package jgb.examples.simplewindow;
002    
003    
004    import jgb.builder.TagHandler;
005    
006    import javax.swing.*;
007    import java.awt.*;
008    import java.util.EventObject;
009    import java.util.Map;
010    
011    public class AcceptDialog {
012        private String expectedUsername;
013        private String expectedPassword;
014    
015        public AcceptDialog(String username, String password) {
016            this.expectedUsername = username;
017            this.expectedPassword = password;
018        }
019    
020        public void handleEvent(Map context, EventObject eventObject) {
021            Map objectsMap = (Map)context.get(TagHandler.OBJECTS_MAP_KEY);
022            final Window loginDialog = (Window)objectsMap.get("loginDialog");
023    
024            final JTextField usernameField = (JTextField)objectsMap.get("usernameField");
025            final String userName = usernameField.getText();
026    
027            final JTextField passwordField = (JTextField)objectsMap.get("passwordField");
028            final String password = passwordField.getText();
029    
030            if (expectedUsername.equals(userName)) {
031                if (expectedPassword.equals(password)) {
032                    JOptionPane.showMessageDialog(loginDialog, "Login accepted !");
033                    loginDialog.setVisible(false);
034                    loginDialog.dispose();
035                }
036            }
037    
038            JOptionPane.showMessageDialog(loginDialog, "Incorrect login...");
039        }
040    }